<template>
	<uni-popup ref="popup" type="center">
		<view class="popup-container">
			<view class="header" :class="{positionHeader:iconUrl}">
				<image v-if="imgUrl" class="background" :src="getImg()" mode="widthFix"></image>
				<image v-if="iconUrl" class="icon" :src="getIcon()" mode="widthFix"></image>
			</view>
			<view class="body" :class="{positionBody:iconUrl}">
				<view class="title">{{title}}</view>
				<view class="content">
					<view class="item" v-for="(item, index) in content" :key="item.id">{{item.value}}</view>
				</view>
				<view class="sub-content" v-if="subContent">{{subContent}}</view>
				<view class="body-form" v-if="type === 2">
					<view class="form-label">我的邮箱</view>
					<input v-model="value" placeholder="请输入" class="form-input" />
					<view class="form-text">本次下载需付费: XXX元</view>
				</view>
			</view>
			<view class="footer" :class="{footer2: subBtnContent&&type === 2 || subBtnContent&&iconUrl}">
				<view class="button" @click="close">{{btnContent}}</view>
				<view class="button" :class="[{info:subBtnContent&&iconUrl}, {sub:subBtnContent}]" v-if="subBtnContent"
					@click="close">{{subBtnContent}}</view>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		props: {
			// 标题, 必传
			title: {
				type: String,
				default: '标题'
			},
			// 内容, 必传
			content: {
				type: Array,
				default: []
			},
			// 子内容, 选传
			subContent: {
				type: String,
				default: ''
			},
			// 背景图地址, 必传-选传 (1.popup-bg  2.popup-bg2 )
			imgUrl: {
				type: String,
				default: ''
			},
			// 背景图icon地址, 选传 (与imgUrl不可同时传)
			iconUrl: {
				type: String,
				default: ''
			},
			// 按钮, 选传
			btnContent: {
				type: String,
				default: '我知道了'
			},
			// 子按钮, 选传 (若未传则不显示)
			subBtnContent: {
				type: String,
				default: ''
			},
			// 类型, 选传 (1.展示 2.带输入框  默认:1)
			type: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				value: ''
			}
		},
		methods: {
			open() {
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()
			},
			getImg() {
				return require(`@/static/${this.imgUrl}.png`)
			},
			getIcon() {
				return require(`@/static/${this.iconUrl}.png`)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.popup-container {
		width: 640upx;
		background-color: #fff;
		border-radius: 40upx;
		position: relative;
		text-align: center;

		.header {
			height: 330upx;

			&.positionHeader {
				width: 178upx;
				height: 138upx;
				padding: 24upx 32upx;
				background-color: #fff;
				border-radius: 50%;
				position: absolute;
				top: -72upx;
				left: 205upx;

				.icon {
					width: 138upx;
					height: 138upx;
				}
			}

			.background {
				width: 100%;
				height: 330upx;
			}
		}

		.body {
			padding: 40upx;

			&.positionBody {
				padding: 120upx 40upx 40upx;

				.title {
					padding-bottom: 40upx;
					border-bottom: 1upx solid #eee;
				}
			}

			.title {
				color: #000;
				font-weight: 600;
				font-size: 32upx;
			}

			.content {
				color: #606366;
				padding: 32upx 0upx;
			}

			.body-form {
				padding: 0 20upx;
				text-align: left;

				.form-label {
					margin-bottom: 12upx;
				}

				.form-input {
					background-color: #eee;
					padding: 16upx 32upx;
					border-radius: 48upx;
					font-size: 30upx;
				}

				.form-text {
					margin-top: 24upx;
					color: #fc5243;
				}
			}

			.sub-content {
				color: #909699;
				padding: 32upx 0upx;
			}
		}

		.footer {
			padding: 0 80upx 40upx;

			&.footer2 {
				display: flex;
				justify-content: space-between;

				.button:first-child {
					margin-right: 16upx;
				}
			}

			.button {
				width: 480upx;
				height: 88upx;
				line-height: 88upx;
				border-radius: 44upx;
				background-color: #53B3D9;
				color: #fff;
				font-size: 30upx;

				&.info {
					background-color: #fff;
					color: #53B3D9;
					border: 1upx solid #53B3D9;
				}

				&.sub {
					background-color: #fff;
					color: #53B3D9;
				}
			}
		}
	}
</style>
